package com.practice.web.controller;

import com.alibaba.fastjson.JSON;
import com.practice.domain.user.User;
import com.practice.web.controller.response.ResponseBean;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;

/**
 * Created by Administrator on 2016/8/20.
 */
public class BaseController {
  public static final String SESSION_USER_KEY = "practiceUserSessionKey";

  protected void saveUser(User user, HttpServletRequest request) {
    request.getSession().setAttribute(SESSION_USER_KEY, user);
  }

  protected User getUser(HttpServletRequest request) {
    return (User)request.getSession().getAttribute(SESSION_USER_KEY);
  }

  protected <T> String toJsonStr(HttpStatus status, T item) {
    return JSON.toJSONString(new ResponseBean<T>(HttpStatus.OK.value(), item));
  }
}
